/*
 * @lc app=leetcode.cn id=942 lang=typescript
 *
 * [942] 增减字符串匹配
 */

// @lc code=start
// TODO 贪心算法，题中要求需要转化为最大最小值的取用
function diStringMatch(s: string): number[] {
    const cache = [...Array(s.length + 1).keys()];
    const result: number[] = [];
    for (let i = 0; i < s.length; i++) {
        const char = s[i];
        if (char === "D") {
            result.push(cache.pop()!);
        }
        if (char === "I") {
            result.push(cache.shift()!);
        }
    }
    result.push(cache[0]);
    return result;
}
// @lc code=end
